﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LongQuanWeb.App_Code;

namespace LongQuanWeb.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["username"] = null;
            }
        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
            //if ((Session["PassErrorCountAdmin"] != null) && (Session["PassErrorCountAdmin"].ToString() != ""))
            //{
            //    int PassErroeCount = Convert.ToInt32(Session["PassErrorCountAdmin"]);
            //    if (PassErroeCount > 3)
            //    {
            //        this.btn_login.Enabled = false;
            //        this.lblMsg.Text = "对不起，你错误登录了三次，系统登录锁定！";
            //        return;
            //    }
            //}

            string userName = this.txt_username.Text.Trim();
            string Password = this.txt_password.Text.Trim();

            //验证登录信息，如果验证通过则返回当前用户对象的安全上下文信息
            string str = "select count(*) from [Admins] where UserName='" + userName + "' AND PassWords='" + Password + "'";
            DataTable dtpass = DbHelperSQL.Query(str).Tables[0];
            if (dtpass.Rows[0][0].ToString() == "0")//登录信息不对         
            {
                this.lblMsg.Text = "登陆失败： " + userName;
                if ((Session["PassErrorCountAdmin"] != null) && (Session["PassErrorCountAdmin"].ToString() != ""))
                {
                    int PassErroeCount = Convert.ToInt32(Session["PassErrorCountAdmin"]);
                    Session["PassErrorCountAdmin"] = PassErroeCount + 1;
                }
                else
                {
                    Session["PassErrorCountAdmin"] = 1;
                }
            }
            else
            {
                Session["username"] = userName;
                Response.Redirect("Index.aspx");

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.txt_password.Text = "";
            this.txt_username.Text = "";
        }
    }
}